#include <bits/stdc++.h>

using namespace std;

class TopVotedCandidate {
	using pii = pair<int, int>;

public:
	TopVotedCandidate(vector<int>& persons, vector<int>& times) {
		vector<int> idxs;
		for (int i = 0, len = persons.size(); i < len; i++) idxs.emplace_back(i);
		sort(begin(idxs), end(idxs), [&](int o1, int o2) { return times[o2] < times[o1]; });
		/* for (int i: idxs) cout << i; */

		unordered_map<int, int> person;
		int max = 0;
		for (int idx: idxs) {
			int man = persons[idx], time = times[idx];
			if (++person[man] >= person[max])
				max = man;
			res[time] =  max;
		}
	}

	int q(int t) {
		auto idx = res.upper_bound(t);
		if (idx == begin(res)) return 0;
		return (--idx)->second;
	}
private:
	map<int, int> res;
};

/**
 * Your TopVotedCandidate object will be instantiated and called as such:
 * TopVotedCandidate* obj = new TopVotedCandidate(persons, times);
 * int param_1 = obj->q(t);
 */

int main()
{
	/* Solution solution; */
	return 0;
}
